<%--
  Created by IntelliJ IDEA.
  User: 三斤
  Date: 2022/11/30
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>投票结果</title>
</head>
<body>
<jsp:useBean id="DB" class="db.conn" />
<%
    String id = request.getParameter("id");
    Connection conn = DB.getConn();
    Statement stmt = DB.getStatement(conn);
    ResultSet rs = DB.getResultSet(stmt,"select * from vote1 where id ="+id);
    int num = 0;
    if(rs.next()){
        num = rs.getInt("count");
        System.out.println(num);
    }
    num++;
    System.out.println(num);
    //空格一定要书写规范，否则sql语句会失败
    String sql = "update vote1 set count ="+num+" where id="+id+"";
    DB.excuteUpdate(stmt,sql);
    DB.close(conn);
    DB.close(stmt);
    DB.close(rs);

%>
<h2>投票结果</h2>
<table align="center" border bordercolor="#0099ff">
    <tr>
        <th bgcolor="#CCFFFF">人物</th>
        <th bgcolor="#CCFFFF">得票数</th>
    </tr>
    <%
        int totalNum1 =0;
        Connection conn1 = DB.getConn();
        Statement stmt1 = DB.getStatement(conn1);
        ResultSet rs1 = DB.getResultSet(stmt1,"select count from vote1");
        while(rs1.next()){
            totalNum1 += rs1.getInt(1);
        }
        DB.close(rs1);
        rs1 = DB.getResultSet(stmt1,"select * from vote1");
        while (rs1.next()){
            out.println("<tr>");
            int num1 = rs1.getInt("count");
            out.println("<td>"+rs1.getString("item")+"</td>");
            out.println("<td>得:"+num1+"票</td>");

        }

        DB.close(conn1);
        DB.close(stmt1);
        DB.close(rs1);
    %>
</table>
<a href="index.jsp"><h3 align="center">返回主页面</h3></a></p>
</body>
</html>